package com.dc.refactoring._5_简化函数调用._8_ReplaceParameterWithMethods;

/**
 * Description: 优化前
 * @author: gdc
 * @date: 2020/12/9
 * @version 1.0
 */
public class Demo1 {

    /**
     * 数量
     */
    private double quantity;
    /**
     * 单价
     */
    private double price;

    public double getPrice(){
        double basePrice = quantity * price;
        int discountLevel;
        if (quantity > 100) {
            discountLevel = 2;
        } else {
            discountLevel = 1;
        }
        double result = disCountedPrice(basePrice, discountLevel);
        return result;
    }

    /**
     * 获取折扣后的价格
     * @param basePrice             总价格
     * @param discountLevel         折扣等级
     * @return                      折扣后价格
     */
    private double disCountedPrice(double basePrice, int discountLevel) {
        if (discountLevel == 2) {
            return basePrice * 0.5;
        }
        return basePrice * 0.8;
    }

}
